home *** CD-ROM | disk | FTP | other *** search
/ PC Format (UK) 188 / 01-04 PC Format 188 [2006-06] DVD side 1_.iso / DiscContents / Workshops / Workshops_Graphics / 3DCanvas / 3DCanvas.msi / Instal01.cab / _5BF6647D067740F6B465E5367E0E6ED4 < prev    next >
Text File  |  2003-10-06  |  9KB  |  217 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "CreateFace"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. Option Explicit
  15.  
  16. '*********************************************************************************
  17. ' In order to provide clear examples this sample code does not incluce any
  18. ' error handling.
  19. '
  20. ' Note that typed variables are used in this example. The scripting references
  21. ' does not type variables since scripting does not permit the use of typed
  22. ' variables. Visual Basic can automatically translate from the format the API
  23. ' provides (usually Variants) to the appropriate type. If you are using a language
  24. ' other than Visual Basic you will likely have to do this yourself.
  25. '*********************************************************************************
  26.  
  27. Implements Plugin
  28.  
  29. '*********************************************************************************
  30. ' Module Level Constants
  31. '*********************************************************************************
  32.  
  33. Const mstrcModule As String = "CreateFace"
  34.  
  35. '*********************************************************************************
  36. ' Class Events
  37. '*********************************************************************************
  38.  
  39. '*********************************************************************************
  40. ' Implemented Functions
  41. '*********************************************************************************
  42.  
  43. '*********************************************************************************
  44. ' Purpose: Creates a Face
  45. '*********************************************************************************
  46.  
  47. Private Sub Plugin_Apply(Canvas As CanvasApplication _
  48. , UserDataSingles() As Single _
  49. , UserDataLongs() As Long _
  50. , UserDataString As String)
  51.  
  52.     Dim Scene As CanvasScene            'The current active scene
  53.     Dim SceneRootGroup As CanvasGroup   'The root Group of the scene
  54.     Dim Group As CanvasGroup            'The Group for our object (face)
  55.     Dim Object As CanvasObject          'The object we are creating (face)
  56.     Dim Face As CanvasFace              'The face we are creating
  57.     Dim GridOriginX As Single           'The 3D Canvas Grid's Origin (x)
  58.     Dim GridOriginY As Single           'The 3D Canvas Grid's Origin (y)
  59.     Dim GridOriginZ As Single           'The 3D Canvas Grid's Origin (z)
  60.     Dim GridSize As Single              'The 3D Canvas Grid's Size
  61.     Dim GridInterval As Single          'The 3D Canvas Grid's Interval
  62.     Dim Points As String                'The user's desired # of points
  63.     Dim NumericPoints As Long           'Points converted to a number
  64.     Dim FirstPointX As Single           'First point in face
  65.     Dim FirstPointY As Single           'First point in face
  66.     Dim FirstPointZ As Single           'First point in face
  67.     Dim AxisX As Single                 'Axis to rotate the start position around
  68.     Dim AxisY As Single                 'Axis to rotate the start position around
  69.     Dim AxisZ As Single                 'Axis to rotate the start position around
  70.     Dim Point As Long                   'Point we are creating
  71.     Dim NewPointX As Single             'Point to add
  72.     Dim NewPointY As Single             'Point to add
  73.     Dim NewPointZ As Single             'Point to add
  74.     Dim BoxMinX As Single               'The Object's Bounding Box
  75.     Dim BoxMinY As Single               'The Object's Bounding Box
  76.     Dim BoxMinZ As Single               'The Object's Bounding Box
  77.     Dim BoxMaxX As Single               'The Object's Bounding Box
  78.     Dim BoxMaxY As Single               'The Object's Bounding Box
  79.     Dim BoxMaxZ As Single               'The Object's Bounding Box
  80.     Dim Material As CanvasMaterial      'The Face's Material
  81.  
  82.     'ask the user how many points s/he wants
  83.     Do
  84.         Points = InputBox("How many points would you like in the face?", , "4")
  85.  
  86.         'if they entered anything
  87.         If Points <> "" Then
  88.             'they could have entered anything so ensure it is valid
  89.             On Error Resume Next
  90.             NumericPoints = CLng(Points)
  91.             Err.Clear
  92.             On Error GoTo 0
  93.  
  94.             'Let them know we had a problem
  95.             If NumericPoints < 3 Then
  96.                 MsgBox "3 is the minimum number of points", vbInformation
  97.             End If
  98.         End If
  99.     Loop Until NumericPoints >= 3 Or Points = ""
  100.  
  101.     'If they entered anything continue
  102.     If Points <> "" Then
  103.  
  104.         'get the scene
  105.         Set Scene = Canvas.GetActiveScene
  106.  
  107.         'get the root Group
  108.         Set SceneRootGroup = Scene.GetRootGroup
  109.  
  110.         'create a Group for the object (face)
  111.         Set Group = Scene.CreateGroup
  112.  
  113.         'add it to the scene
  114.         SceneRootGroup.AddChild Group
  115.  
  116.         'give the Group a name - note that we can't do this
  117.         'until the Group is added to the scene
  118.         Group.SetName "Face Group"
  119.  
  120.         'create an object
  121.         Set Object = Scene.CreateObject()
  122.  
  123.         'add the face to the object
  124.         Set Face = Object.CreateFace
  125.  
  126.         'add a dummy normal to the object (we need one to add the points)
  127.         Object.AddNormal 0, 0, -1
  128.  
  129.         'set the FirstPoint
  130.         FirstPointX = 0
  131.         FirstPointY = 0.5
  132.         FirstPointZ = 0
  133.  
  134.         'we're going to make an exception if they want four faces
  135.         'a quad will look wrong if we just rotate around a point
  136.         If NumericPoints = 4 Then
  137.             'add the quad points to the object
  138.             Object.AddPoint -0.5, -0.5, 0
  139.             Object.AddPoint -0.5, 0.5, 0
  140.             Object.AddPoint 0.5, 0.5, 0
  141.             Object.AddPoint 0.5, -0.5, 0
  142.  
  143.             'add the points and the normal to the face
  144.             Face.AddPointAndNormal 0, 0
  145.             Face.AddPointAndNormal 1, 0
  146.             Face.AddPointAndNormal 2, 0
  147.             Face.AddPointAndNormal 3, 0
  148.         Else
  149.             'add the points to the object
  150.             For Point = 0 To NumericPoints - 1
  151.                 'rotate the FirstPoint to get a NewPoint
  152.                 Canvas.RotatePoint FirstPointX, FirstPointY, FirstPointZ, 0, 0, -1, 6.2831853 / NumericPoints * Point, NewPointX, NewPointY, NewPointZ
  153.  
  154.                 'add the NewPoint to the object
  155.                 Object.AddPoint NewPointX, NewPointY, NewPointZ
  156.  
  157.                 'add the point to the face
  158.                 Face.AddPointAndNormal Point, 0
  159.             Next
  160.         End If
  161.  
  162.         'Create an appropriate material for the face
  163.         Set Material = Scene.CreateMaterial
  164.  
  165.         'make it a nice color
  166.         Material.SetColor 0.894, 0.773, 0.788
  167.  
  168.         'set the default diffuse value
  169.         Material.SetDiffuse 60
  170.  
  171.         'set the default ambient value
  172.         Material.SetAmbient 20
  173.  
  174.         'apply the material to the face
  175.         Face.SetMaterial Material
  176.  
  177.         'add the object to the created Group
  178.         'this also triggers the update to the database
  179.         Group.AddObject Object
  180.  
  181.         'set the object name - note that we can't do this until
  182.         'the object is added to a Group
  183.         Object.SetName "Face"
  184.  
  185.         'Now that we know the size of the object let's set the position of the Group
  186.         'so the face is visible
  187.         
  188.         'get the 3D Canvs grid details
  189.         Canvas.GetGridDetails GridOriginX, GridOriginY, GridOriginZ, GridSize, GridInterval
  190.  
  191.         'get the object's dimensions
  192.         Object.GetBoundingBox BoxMinX, BoxMinY, BoxMinZ, BoxMaxX, BoxMaxY, BoxMaxZ
  193.  
  194.         'Center the Object's Group on the Scene and have the object sitting nicely
  195.         'on the surface
  196.         Group.SetPosition SceneRootGroup, 0, GridOriginX + GridSize / 2, GridOriginY - BoxMinY, GridOriginZ + GridSize / 2
  197.  
  198.     End If
  199. End Sub
  200.  
  201. '*********************************************************************************
  202. ' Purpose: Identifies the name of the plug-in to 3D Canvas
  203. '*********************************************************************************
  204.  
  205. Private Function Plugin_GetName() As String
  206.     Plugin_GetName = "Create Face"
  207. End Function
  208.  
  209. '*********************************************************************************
  210. ' Purpose: Identifies the author of the plug-in to 3D Canvas
  211. '*********************************************************************************
  212.  
  213. Private Function Plugin_GetAuthor() As String
  214.     Plugin_GetAuthor = "Amabilis Software"
  215. End Function
  216.  
  217.